import {useSettings} from "../stores/Settings";
import {onMounted, Ref, ref} from "vue";

export default function () {
  const stores = useSettings()
  // 时间颜色
  let timercolor: Ref<string> = ref('')
  // 描述颜色
  let describecolor: Ref<string> = ref('')
  // 图标颜色
  let iconcolor: Ref<string> = ref('')
  // 自定义描述展示选项
  let customdescription: Ref<string> = ref('')
  // 自定义描述文字
  let customtext: Ref<string> = ref('')
  // 倒计时
  let countdown: Ref<string> = ref('')

  /**
   * 修改时间颜色
   * @param value
   */
  const updateTimerColor = (value): void => {
    if (value) {
      stores.timercolor = value
      localStorage.setItem("timercolor", stores.timercolor)
    }
  }
  /**
   * 修改描述颜色
   * @param value
   */
  const updateDescribeColor = (value): void => {
    if (value) {
      stores.describecolor = value
      localStorage.setItem("describecolor", stores.describecolor)
    }
  }
  /**
   * 修改图标颜色
   * @param value
   */
  const updateIconColor = (value): void => {
    if (value) {
      stores.iconcolor = value
      localStorage.setItem("iconcolor", stores.iconcolor)
    }
  }
  /**
   * 修改描述展示内容
   * @param value
   */
  const updateDescribeValue = (value): void => {
    if (value) {
      stores.customdescription = value
      localStorage.setItem("customdescription", stores.customdescription)
    }
  }
  /**
   * 修改自定义描述展示内容
   * @param value
   */
  const updateDescribeText = (value): void => {
    if (value) {
      stores.customtext = value
      localStorage.setItem("customtext", stores.customtext)
    }
  }
  /**
   * 修改倒计时
   * @param value
   */
  const updateCountDown = (value): void => {
    if (value) {
      stores.countdown = value
      localStorage.setItem("countdown", stores.countdown)
    }
  }

  onMounted(() => {
    timercolor.value = stores.timercolor
    describecolor.value = stores.describecolor
    iconcolor.value = stores.iconcolor
    customdescription.value = stores.customdescription
    customtext.value = stores.customtext
    countdown.value = stores.countdown
  })
  return {
    timercolor,
    describecolor,
    iconcolor,
    customdescription,
    customtext,
    countdown,
    updateTimerColor,
    updateDescribeColor,
    updateIconColor,
    updateDescribeValue,
    updateDescribeText,
    updateCountDown
  }
}
